Array.prototype.swap = function(originIndex,targetIndex) {
    let temp = this[originIndex]
    this[originIndex] = this[targetIndex]
    this[targetIndex] = temp
}

function bubble(arr) {
    for(let i =0; i < arr.length - 1;i++) {
        for(let j = 0; j < arr.length - 1 - i;j++) {
            if(arr[j] > arr[j + 1]) {
                arr.swap(j , j + 1)
            }
        }
    }
    return arr
}
console.log(bubble([1,2,3,4,3,4,1,2]));
